<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * SimplyPost
 *
 * @author		Pascal Kriete
 * @package		SimplyPost
 * @copyright	Copyright (c) 2008, Pascal Kriete
 * @license 	http://www.gnu.org/licenses/lgpl.txt
 */

// ------------------------------------------------------------------------

/**
 * Forum Controller
 *
 * @package		SimplyPost
 * @subpackage	Forum
 * @category	Controller
 * @author		Pascal Kriete
 */

class Forum extends BaseController {
	
	/**
	 * Constructor
	 *
	 * @access	public
	 */
	function Forum()
	{
		parent::BaseController();
		$this->lang->load('forum');
		$this->load->helper('date');
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * No real usage - redirects
	 *
	 * @access	public
	 */
	function index()
	{
		$this->session->set_flashdata('msg', $this->lang->load('forum_not_exist'));
		redirect('/');
	}
	
	// --------------------------------------------------------------------

	/**
	 * Shows the requested forum
	 *
	 * @access	public
	 */
	function view($id = -1)
	{
		if ($id == -1)
		{
			$this->session->set_flashdata('msg', $this->lang->load('forum_not_exist'));
			redirect('/');
		}
		
		$this->breadcrumb->from_db($id, 'forum');
		
		/* Grab category name and child names/ids */
		$this->load->model('Top_model', 'Topic');
		$for_info = $this->Topic->get_info($id);
				
		$data = $for_info[0];
		
		$tmp = $this->Topic->get_topics($data['id']);
		
		$data['topics'] = array();
		$data['empty'] = 1;
		
		//Topic variables ... append t_ (this is stupid, find a better way)
		if ($tmp[0] != -1)
		{
			$data['empty'] = 0;
			
			foreach($tmp as $row)
			{
				$row_tmp = array();
				foreach($row as $key => $val)
				{
					$row_tmp['t_'.$key] = $val;
				}
				$data['topics'][] = $row_tmp;
			}
		}
		
		
		set_title(ucfirst($data['name']));
		
		$this->load->model('Post_model', 'Post');
		
		$this->parser->parse('forum/list', $data);
	}
}